// 新建router/index.js,引入组件进行路由配置，导出router实例
import React from "react"
import { createBrowserRouter, redirect, type RouteObject } from "react-router-dom"
import App from "../App"
// const Home = React.lazy(() => import('../pages/Home'));
// const Login = React.lazy(() => import('../pages/Login'));

import Home from '../pages/Home';
import Login from '../pages/Login';
import NotFound from '../pages/NotFound';

const routes: RouteObject[] = [
    {
        path: '/',
        Component: App,
        children: [
            { index: true, Component: Home, loader: () => {
                if(localStorage.getItem('token')) {
                    return null
                }
                return redirect('/login')
            } },
            { path: '/login', Component: Login },
            {
                path: '*',
                Component: NotFound
            }
        ]
    }
];

const router = createBrowserRouter(routes);

export default router



